<template>
	<view>
		<view class="title">登录</view>
		<!--头部logo -->
		<view class="header flex justify-center align-center">
			<view class="logo flex flex-direction justify-center align-center">
				<image src="../../static/img/login-img/login.png" mode="aspectFit" style="position: absolute; width: 436upx; height: 304upx;"></image>
				<image class="logo-img" src="/static/img/login-img/logo.png" mode="aspectFit"></image>
				<view>北象科技</view>
				<view>商家助手</view>
			</view>
		</view>

		<!-- 输入框 -->
		<view class="flex flex-direction align-center">
			<view class="container flex align-center justify-between">
				<text>账号</text>
				<input class="input" type="text" maxlength="11" placeholder="请输入您的手机号码" v-model="account.username" autofocus="autofocus" />
			</view>
			<view class="container flex align-center justify-between">
				<text>密码</text>
				<input class="input" type="password" maxlength="6" placeholder="请输入您的密码" v-model="account.password"/>
			</view>
		</view>
		<!-- 登录按钮 -->
		<view class="padding ">
			<button class="cu-btn block line-blue margin-tb-sm lg" :disabled="isDisb" @click="handLogin">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: {
					username: '大黄',
					password: '123456'
				}
			};
		},
		methods: {
			handLogin() {
				this.$http.post('assemble/user/login', {
					userName: this.account.username,
					passWord: this.account.password
				}).then((res) => {
					console.log(res)
					if (res.data.flag == true) {
						uni.setStorage({
							key: 'userInfo',
							data: {
								roleId: res.data.data.roleId,
								storeId: res.data.data.storeId,
								storeName: res.data.data.storeName,
								userId: res.data.data.userId
							},
							success() {
								uni.redirectTo({
									url: '/pages/index/index'
								})
							}
						})
					}else if(res.data.flag == false){
						uni.showToast({
						    title: res.data.message,
						    duration: 2000,
								icon:'none'
						});
					}
				}).catch((err) => {
					console.log(err)
				})
			}
		},
		computed: {
			isDisb() {
				if (this.account.username != '' && this.account.password != '') return false
				else {
					return true
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		font-size: $font34;
		letter-spacing: 2upx;
		font-weight: 500;
		margin: 71upx 0 49upx 56upx;
	}

	.header {
		letter-spacing: 2upx;
		width: 750upx;
		height: 350upx;
		background-color: $global-bgc;
		.logo {
			color: #ffffff;
			.logo-img {
				width: 116upx;
				height: 116upx;
				background-color: #FFFFFF;
				border: 10upx solid #FFFFFF;
				border-radius: 50%;
				margin-bottom: 35upx;
			}
			view:nth-child(3) {
				font-size: $font40;
				margin-bottom: 10upx;
			}
			view:nth-child(4) {
				font-size: $font26;
			}
		}
	}
	.container {
		width: 690upx;
		height: 106upx;
		font-size: $font32;
		letter-spacing: 2upx;
		border-bottom: 1upx solid #EEEEEE;
		.input {
			width: 305upx;
			text-align: right;
		}
	}
	
	.cu-btn[class*="line"] {
		background-color: $global-bgc;
		color: #FFFFFF;
		letter-spacing: 5upx;
	}
</style>
